package com.eleadmin.common.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eleadmin.common.system.mapper.CreditRatingMapper;
import com.eleadmin.common.system.service.CreditRatingService;
import com.eleadmin.common.system.entity.CreditRating;
import com.eleadmin.common.system.param.CreditRatingParam;
import com.eleadmin.common.core.web.PageParam;
import com.eleadmin.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 信用等级表Service实现
 *
 * @author EleAdmin
 * @since 2025-04-30 20:57:55
 */
@Service
public class CreditRatingServiceImpl extends ServiceImpl<CreditRatingMapper, CreditRating> implements CreditRatingService {

    @Override
    public PageResult<CreditRating> pageRel(CreditRatingParam param) {
        PageParam<CreditRating, CreditRatingParam> page = new PageParam<>(param);
        //page.setDefaultOrder("create_time desc");
        List<CreditRating> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<CreditRating> listRel(CreditRatingParam param) {
        List<CreditRating> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<CreditRating, CreditRatingParam> page = new PageParam<>();
        //page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public CreditRating getByIdRel(Integer id) {
        CreditRatingParam param = new CreditRatingParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

    @Override
    public CreditRating getByUserId(Integer userId) {
        QueryWrapper<CreditRating> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return baseMapper.selectOne(queryWrapper);
    }
}
